package com.normal.zbase.impl.tools.extend

import ch.qos.logback.classic.LoggerContext
import ch.qos.logback.classic.joran.JoranConfigurator
import ch.qos.logback.core.joran.spi.JoranException
import com.normal.zbase.R
import com.normal.zbase.impl.manager.AppManager
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.io.InputStream


/**
 * Created by zsf on 2021/1/11 14:25
 * ******************************************
 * * 自定义日志
 * ******************************************
 */

val loggerApi: Logger get() = LoggerFactory.getLogger("logNormal")

val logger: Logger get() = LoggerFactory.getLogger("apiNormal")

open class Logs {
    companion object {
        @JvmStatic
        val instance: Logs by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
            Logs()
        }
    }

    fun logger() = logger

    fun initLogback() {
        // reset the default context (which may already have been initialized)
        // since we want to reconfigure it
        val lc = LoggerFactory.getILoggerFactory() as LoggerContext
        lc.stop()
        val config = JoranConfigurator()
        config.context = lc
        val stream: InputStream
        try {
            stream = AppManager.mContext.getResources().openRawResource(R.raw.logback)
            config.doConfigure(stream)
        } catch (e: JoranException) {
            e.printStackTrace()
        }
    }

}








